<template>
  <div class="gallery-container" @click="handleGalleryClick">
    <div class="image-wrapper">
      <swiper :options="swiperOptions">
        <swiper-slide v-for="(item, index) of imgsList" :key="index">
          <img class="swiper-img" :src="item" />
        </swiper-slide>
        <div class="swiper-pagination" slot="pagination"></div>
      </swiper>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    imgsList: {
      type: Array,
      default: function() {
        return [];
      }
    }
  },
  data() {
    return {
      swiperOptions: {
        pagination: ".swiper-pagination",
        paginationType: "fraction",
        // 动态显示隐藏轮播图导致宽度计算失误，显示异常，需要增加如下两个属性
        observer: true,
        observeParents: true
      }
    };
  },
  methods: {
    handleGalleryClick() {
      this.$emit("closeGallery");
    }
  }
};
</script>

<style lang="stylus" scoped>
div {
  display: flex;
}

.gallery-container >>> .swiper-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.gallery-container {
  flex-direction: column;
  justify-content: center;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: #000;
  z-index: 3;
}

.gallery-container .image-wrapper {
  position: absolute;
  width: 100%;
  height: 0;
  padding-bottom: 70%;
  color: #fff;
}

.gallery-container .image-wrapper .swiper-img {
  width: 100%;
  height: 100%;
}

.gallery-container .image-wrapper .swiper-pagination {
  bottom: -1rem;
  justify-content: center;
}
</style>
